<?php

namespace app\common\model;


class MailCodeModel extends BaseModel
{
    // 设置当前模型对应的完整数据表名称
    protected $table = 'tp_mail_code';

    /*
    获取验证码
     */
    public function getMailCode($mail,$type=1){
    	$code = $this->where('mail', $mail)
					    	->where('type', $type)
					    	->where('pass_time', '>', time())
					    	->order('id desc')
					    	->value('code');
    	return $code;
    }

    /*
    添加验证码
     */
    public function addCode($mail,$code,$type=1){
		$res = $this->insert([
                'mail' => $mail,
                'code' => $code,
                'type' => $type,
                'pass_time' => time() + 600
                    ]
            );
		return $res;
    }

    /*
    验证码计数
     */
    public function countMail($mail){
        $data = $this->where('mail',$mail)->where('pass_time','>',strtotime(date('Y-m-d',time())))->count();
        return $data;
    }   
}